package com.acwer.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * REST请求统一返回消息体
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "HTTP消息体",description ="REST统一返回实体" )
public class RpnMsg<DATA> implements Serializable {

    //返回码
    @ApiModelProperty("返回码")
    private int code;
    //错误消息
    @ApiModelProperty("错误消息")
    private String msg;
    //返回的数据
    @ApiModelProperty("消息结果")
    private DATA data;

    /**
     * 成功消息
     * @return
     */
    public static RpnMsg SUCCESS(){
        return new RpnMsg(0,"操作成功！",null);
    }

    public static<T> RpnMsg<T> SUCCESS(T data){
        return new RpnMsg<T>(0,"操作成功！",data);

    }

    public static RpnMsg FAIL(){
        return new RpnMsg(1,"操作失败！",null);
    }

}
